<%--
  Created by IntelliJ IDEA.
  User: ZhuChunXiao
  Date: 2017/6/1
  Time: 15:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
  String _id=request.getParameter("_");
  String jsessionid = session.getId();
%>

<div class="row">
  <div class="col-lg-12">
    <div class="panel">
      <div class="panel-heading header">
        <h3 class="panel-title" id="title">订单实施表</h3>
      </div>

      <!-- BASIC FORM ELEMENTS -->
      <!--===================================================-->
      <form id="form_order_input" class="panel-body form-horizontal form-padding">
        <input type="hidden" name="keyId" id="keyId" value="${order.id}" />
        <input type="hidden" name="curDutyId" id="curDutyId" value=""/>

        <div class="form-group">
          <label class="col-md-2 control-label">
            <a href="javascript:void(0);" onclick="fn_contract_dialog_select('name','contractId')" style="color: #0a6dbd">订单合同</a>
            <i class="fa fa-asterisk txt-color-red"></i>
          </label>
          <div class="col-md-6">
            <input type="text" id="name" name="name" class="form-control" value="${order.name}" placeholder="请选择订单合同" disabled>
            <input type="hidden" name="contractId" id="contractId" value="${contractId.id}" />
          </div>
        </div>

        <div class="form-group">
          <label class="col-md-2 control-label">订单客户<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-6">
            <input disabled type="text" id="customer" name="customer" class="form-control" value="${order.name}">
          </div>
        </div>

        <div class="form-group">
          <label class="col-md-2 control-label">订单编号<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-6">
            <input type="number" id="orderNo" name="orderNo" class="form-control" placeholder="请输入订单编号" value="${order.orderNo}">
          </div>
        </div>

        <div class="form-group">
          <label class="col-md-2 control-label">订单金额<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-6">
            <input type="number" id="money" name="money" class="form-control" placeholder="请输入订单金额" value="${money}">
          </div>
        </div>

        <div class="form-group">
          <label class="col-md-2 control-label">订单具体需求<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-6">
            <input type="text" id="content" name="content" class="form-control" placeholder="请输入订单具体需求" value="${order.content}">
          </div>
        </div>

        <div class="form-group">
          <label class="col-md-2 control-label">相关附件<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-6">
            <input name="uploadify" id="filename" placeholder="" type="file" >
            <input name="fileId" id="fileId" style="display: none" value="${fileId}">
          </div>
        </div>

        <div class="form-group div-Hidden">
          <label class="col-md-2 control-label">订单下达时间<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-6">
            <div class="input-group date">
              <input type="text" class="form-control" id="issuedDate" name="issuedDate" placeholder="请选择订单下达时间"
                     value=<fmt:formatDate pattern="yyyy-MM-dd" value="${order.issuedDate}" /> >
              <span class="input-group-addon"><i class="ti-calendar"></i></span>
            </div>
          </div>
        </div>

        <div class="form-group div-Hidden">
          <label class="col-md-2 control-label">期望交付时间<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-6">
            <div class="input-group date">
              <input type="text" class="form-control" id="deliverDate" name="deliverDate" placeholder="请选择期望交付时间"
                     value=<fmt:formatDate pattern="yyyy-MM-dd" value="${order.deliverDate}" /> >
              <span class="input-group-addon"><i class="ti-calendar"></i></span>
            </div>
          </div>
        </div>

        <div class="form-group">
          <label class="col-md-2 control-label">备注</label>
          <div class="col-md-6">
            <input type="text" id="remarks" name="remarks" class="form-control" placeholder="请输入备注" value="${order.remarks}">
          </div>
        </div>


        <div class="form-group">
          <label class="col-md-2 control-label">提交人</label>
          <div class="col-md-2">
            <p class="form-control-static">${order.creater.name}</p>
          </div>
          <label class="col-md-2 control-label">提交日期</label>
          <div class="col-md-2">
            <p class="form-control-static"><fmt:formatDate pattern="yyyy-MM-dd" value="${order.createTime}" /></p>
          </div>
        </div>

        <div class="panel-footer">
          <a class="btn btn-default" id="apply-re-common" href="javascript:void(0)">
            <i class="fa fa-lg fa-mail-reply"></i> 返回
          </a>
          <a class="btn btn-success" id="btn-save-common" href="javascript:void(0);"><i class="fa fa-lg fa-download"></i> 保存 </a>
          <c:if test="${order==null || order.processState=='Draft'}">
            <a class="btn btn-warning" id="btn-commit-common" href="javascript:void(0);"><i class="fa fa-upload"></i> 提交 </a>
          </c:if>
          <c:if test="${order!=null && order.processState=='Backed'}">
            <a class="btn btn-warning" id="btn-recommit-common" href="javascript:void(0);"><i class="fa fa-upload"></i> 再提交 </a>
          </c:if>
        </div>

      </form>
      <!--===================================================-->
      <!-- END BASIC FORM ELEMENTS -->

    </div>
  </div>
</div>

<script>
  var index = "${index}";
  var todo = "${todo}";
  var remind = "${remind}";
  var record = "${record}";
  var draft =  "${draft}";

  $(function(){
    var pdata= {
      keyId:$("#keyId").val(),
      entityName:"com.fz.us.oa.core.entity.com.OrderEntity"
    };
    multiDuty(pdata);
  });

  // 日期选择
  $('.input-group.date').datepicker({
    format: 'yyyy-mm-dd',
    weekStart: 1,
    autoclose: true,
    todayBtn: 'linked',
    todayHighlight: true,
    language: 'zh-CN'
  });

  // 附件上传
  inputLoad({
    objId:"filename",
    entityName:"fileIds",
    sourceId:"fileId",
    jsessionid:"<%=jsessionid%>"
  });

  // 订单合同选择框
  function fn_contract_dialog_select(nameField,idField) {
    alert("还没有做这个....");
    return false;
    __open_dialog_select('选择订单合同', '<%=path%>/com/asset/dialogs?category=4', function (dialogRef) {
      var callback = function (data) {
        if (data) {
          dialogRef.close();

          // 获取 user
          $('#'+idField).val(data.id);
          $('#'+nameField).val(data.name);

          $('#customer').val(data.customer);
        } else {
          dialogRef.enableButtons();
        }
      };
      fn_dialog_asset_select(callback);
    });
  }

  //校验
  function infoValidate() {
    var tmp = "";

    tmp = $("input#orderNo").val();
    if(!tmp){
      __toastr_error("请输入订单编号！");
      return false;
    }

    tmp = $("input#money").val();
    if(!tmp){
      __toastr_error("请输入订单金额！");
      return false;
    }else if(tmp==0){
      __toastr_error("订单金额不能为0！");
      return false;
    }

    tmp = $("input#content").val();
    if(!tmp){
      __toastr_error("请输入订单具体需求！");
      return false;
    }

    tmp = $("input#issuedDate").val();
    if(!tmp){
      __toastr_error("请选择订单下达时间！");
      return false;
    }

    tmp = $("input#deliverDate").val();
    if(!tmp){
      __toastr_error("请选择期望交付时间！");
      return false;
    }

    return true;
  }


  //保存
  $("#btn-save-common").click(
          function(e) {
            __confirm_dialog("提示：","确定保存吗？",
                    function () {
                      __form_save("form_order_input", "<%=path%>/com/orderEntity/save",function(){
                        $("#apply-re-common").trigger("click");
                      });
                    }
            )
          }
  );

  //提交
  $("#btn-commit-common,#btn-recommit-common").click(
          function(e) {
            var $valid = infoValidate();
            if(!$valid) return false;

            __confirm_dialog("提示：","提交后填写资料不得修改，请确认是否进行提交？",
                    function () {
                      __form_save("form_order_input", "<%=path%>/com/orderEntity/submit",function(data){
                        if(data.state==1){
                          $("#apply-re-common").trigger("click");
                        }
                      });
                    }
            )
          }
  );

  //返回视图
  $("#apply-re-common").click(function(){
    if(index==1){
      loadURL("menu/dashboard",$('#page-content'));
    }else if(todo==1){
      loadURL("menu/toDo",$('#page-content'));
    }else if(remind==1){
      loadURL("menu/remind",$('#page-content'));
    }else if(record==1){
      loadURL("menu/taskRecord?type=1",$('#page-content'));
    }else if(record==2){
      loadURL("menu/taskRecord?type=2",$('#page-content'));
    }else if(draft==1){
      loadURL("menu/draft",$('#page-content'));
    }else{
      returnToHashUrl()
    }
  });


</script>